<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php

function GetIP(){
if(!empty($_SERVER["HTTP_CLIENT_IP"])) {
  $cip = $_SERVER["HTTP_CLIENT_IP"];
} else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
  $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if(!empty($_SERVER["REMOTE_ADDR"])){
  $cip = $_SERVER["REMOTE_ADDR"];
}
else{
  $cip = "Unknown User";
}
  return $cip;
}

$uname = GetIP();

echo "uname : " . $uname . "<br/>";
echo "pid : " . $_POST["pid"] . "<br/>";
echo "comment : " . $_POST["comment"] . "<br/>";

$con = mysql_connect("localhost","root","123456");
if (!$con) {
  echo "my sql not connect<br/>";
} else if ($_POST["comment"] != "") {
  echo "mysql connected!<br/>";

  mysql_select_db("platform", $con);
  mysql_query("insert into comments values(NULL, '" . $uname . "', '" . $_POST["comment"] . "', " . $_POST["pid"] . ")");

  mysql_close($con);
}

echo "<script>location.href='http://10.120.137.109/platform/index.php?page=" . $_POST['page'] . "';</script>";

?>